<template>
	<view class="padding30rpx">
		<view class="login-font">
			<view>忘记密码</view>
		</view>
		<view>
			<view class="login-marg">手机号</view>
			<view class="line" style="padding-bottom: 30rpx;">
				<input v-model="mobile" placeholder="请输入手机号" />
			</view>
		</view>
		<view>
			<view class="login-marg">验证码</view>
			<view class="line dis" style="padding-bottom: 30rpx;">
				<input type="password" v-model="code" placeholder="请输入验证" />
				<label v-show="show" @tap="fa">发送验证码</label>
				<label style="color: #606266;" v-show="!show">{{verifyTip}}秒重发</label>
			</view>
		</view>

		<button @tap="enter">验证手机号</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				mobile: '',
				code: '',
				password: '',
				verifyTip: 60,
				show: true
			}
		},
		methods: {
			//注册
			enter() {
				var vm = this
				// if(this.mobile == '' ){
				// 	uni.showToast({
				// 		title: "请输入手机号",
				// 		icon: 'none'
				// 	});
				// }
				// else if( this.code == '')
				if (!(/^1[3456789]\d{9}$/.test(this.mobile))) {
					// return
					uni.showToast({
						title: "手机号码不正确",
						icon: 'none'
					});
					return false;

				}
				if (this.code.length < 6) {
					this.$mHelper.toast('验证码格式错误')
					return false;
				}
				this.$http.get('app/UserController/verification', {
					phone: this.mobile,
					code: this.code
				}).then(res=>{
					if(res.code==200){
						uni.redirectTo({
							url: '/pages/user/wangji/wangji?phone=' + this.mobile
						})
					}else{
						this.$mHelper.toast(res.message)
					}
				})
				



			},
			timedown(num) {
				var that = this;
				if (num == 0) {
					that.show = true; // 是否显示获取验证码
					return clearTimeout();
				} else {
					that.show = false; // 是否显示获取验证码
					setTimeout(function() {
						that.verifyTip = num - 1
						that.timedown(num - 1);
					}, 1000); //定时每秒减一  
				}
			},
			//发送验证码
			fa() {

				if (this.mobile == '') {
					uni.showToast({
						icon: 'none',
						title: '请输入手机号'
					})
				} else {
				

					var vm = this
					uni.request({
						method: 'GET',
						url: this.$api + '/app/UserController/getVerificationCode',
						data: {
							phone: vm.mobile,
						},
						success: (res) => {
							console.log(res.data)
							if (res.data.code == 200) {
								uni.showToast({
									icon: 'success',
									title: '验证发送成功！'
								})
								this.show = false
								this.timedown(this.verifyTip)
							} else {
								uni.showToast({
									icon: 'none',
									title: '验证发送失败！'
								})
							}
						},
						fail: (err) => {
							console.log(err)
						}
					})
				}

			},
		}
	}
</script>

<style lang="scss" scoped>
	button {
		margin-top: 256rpx;
		background-color: #00a29a;
		color: #FFFFFF;
		height: 92rpx;
		line-height: 92rpx;
		width: 100%;
	}

	input {
		font-size: 28rpx;
	}

	label {
		color: #007AFF;
	}

	.login-top {
		text-align: center;
		margin: 30rpx 0;

		image {
			width: 229rpx;
			height: 124rpx;

		}
	}

	.login-font {
		font-size: 40rpx;
		font-weight: 600;
		padding-bottom: 30rpx;
	}

	.login-marg {
		margin: 30rpx 0;
		font-size: 32rpx;
	}
</style>
